package com.company.management.exception;


import java.util.regex.Matcher;

public class MessageException extends RuntimeException {

    public MessageException(String message) {
        super(message);
    }

    public MessageException(String message, Object... args) {
        super(formatMessage(message, args));  // 格式化消息并传递给父类构造函数
    }

    private static String formatMessage(String message, Object... args) {
        if (args != null) {
            for (Object arg : args) {
                // 用 {} 替换占位符
                message = message.replaceFirst("\\{}", Matcher.quoteReplacement(String.valueOf(arg)));
            }
        }
        return message;
    }
}
